<?php

/**
 * 公用方法
 */

class Edm_Common {
    /* 默认分页个数 */

    public $defaultPageSize = 10;

    /**
     * @return string ip地址
     */

    public function getIp() {
        if (!empty($_SERVER["HTTP_CLIENT_IP"])) {
            $ip = $_SERVER["HTTP_CLIENT_IP"];
        } elseif (!empty($_SERVER["HTTP_X_FORWARDED_FOR"])) {
            $ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
        } elseif (!empty($_SERVER["REMOTE_ADDR"])) {
            $ip = $_SERVER["REMOTE_ADDR"];
        } else {
            $ip = "unknown";
        }

        return $ip;
    }

    /**
     * 获取当前url
     * @param bool $is_coding 是否需要编码
     * @param string $protocol 协议
     * @return string url地址
     */

    public function getUrl($is_coding = true, $protocol = 'http') {
        $url = $protocol . '://' . $_SERVER['SERVER_NAME'];
        $url .= $_SERVER["SERVER_PORT"] == 80 ? '' : ':' . $_SERVER["SERVER_PORT"];
        $url .= $_SERVER["REQUEST_URI"];
        return $is_coding ? base64_encode($url) : $url;
    }
    
    /**
     * @desc 解码url
     * 
     */
    public function deURL($url) {
        return base64_decode($url);
    }


    /**
     * 信息提示
     * @param string $uri 跳转地址
     * @param string @msg 提示内容
     * @param string @type 提示种类
     * @return void
     */

    public function msg($uri, $msg = '', $type = 'Success') {
        $obj = new Zend_Controller_Action_Helper_Redirector();
        $action = 'index';
        $controller = 'message';
        $module = 'admin';
        $obj->gotoSimpleAndExit($action, $controller, $module, array('type' => $type, 'msg' => $msg, 'uri' => $uri));
    }

}

